using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using AlphaWebsite.Models;

namespace AlphaWebsite.Controllers
{   
    public class WeddingPlanRelatedUsersController : Controller
    {
		private readonly IUserRepository userRepository;
		private readonly IWeddingPlanRelatedUsersRepository weddingplanrelatedusersRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public WeddingPlanRelatedUsersController() : this(new UserRepository(), new WeddingPlanRelatedUsersRepository())
        {
        }

        public WeddingPlanRelatedUsersController(IUserRepository userRepository, IWeddingPlanRelatedUsersRepository weddingplanrelatedusersRepository)
        {
			this.userRepository = userRepository;
			this.weddingplanrelatedusersRepository = weddingplanrelatedusersRepository;
        }

        //
        // GET: /WeddingPlanRelatedUsers/

        public ViewResult Index()
        {
            return View(weddingplanrelatedusersRepository.AllIncluding(weddingplanrelatedusers => weddingplanrelatedusers.User));
        }

        //
        // GET: /WeddingPlanRelatedUsers/Details/5

        public ViewResult Details(System.Guid id)
        {
            return View(weddingplanrelatedusersRepository.Find(id));
        }

        //
        // GET: /WeddingPlanRelatedUsers/Create

        public ActionResult Create()
        {
			ViewBag.PossibleUsers = userRepository.All;
            return View();
        } 

        //
        // POST: /WeddingPlanRelatedUsers/Create

        [HttpPost]
        public ActionResult Create(WeddingPlanRelatedUsers weddingplanrelatedusers)
        {
            if (ModelState.IsValid) {
                weddingplanrelatedusersRepository.InsertOrUpdate(weddingplanrelatedusers);
                weddingplanrelatedusersRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleUsers = userRepository.All;
				return View();
			}
        }
        
        //
        // GET: /WeddingPlanRelatedUsers/Edit/5
 
        public ActionResult Edit(System.Guid id)
        {
			ViewBag.PossibleUsers = userRepository.All;
             return View(weddingplanrelatedusersRepository.Find(id));
        }

        //
        // POST: /WeddingPlanRelatedUsers/Edit/5

        [HttpPost]
        public ActionResult Edit(WeddingPlanRelatedUsers weddingplanrelatedusers)
        {
            if (ModelState.IsValid) {
                weddingplanrelatedusersRepository.InsertOrUpdate(weddingplanrelatedusers);
                weddingplanrelatedusersRepository.Save();
                return RedirectToAction("Index");
            } else {
				ViewBag.PossibleUsers = userRepository.All;
				return View();
			}
        }

        //
        // GET: /WeddingPlanRelatedUsers/Delete/5
 
        public ActionResult Delete(System.Guid id)
        {
            return View(weddingplanrelatedusersRepository.Find(id));
        }

        //
        // POST: /WeddingPlanRelatedUsers/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(System.Guid id)
        {
            weddingplanrelatedusersRepository.Delete(id);
            weddingplanrelatedusersRepository.Save();

            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing) {
                userRepository.Dispose();
                weddingplanrelatedusersRepository.Dispose();
            }
            base.Dispose(disposing);
        }
    }
}

